<?php
if(!interface_exists('XProxy', false)){
	require_once(XFRAMEWORK_DIR.'/core/context/XProxy.php');
}
if(!class_exists('XObject', false)){
	require_once(XFRAMEWORK_DIR.'/core/context/XObject.php');
}
class XClassProxy extends XObject implements XProxy{
	protected $delegate = null;
	protected $factory = null;
	
	public function __construct(XClassFactory $factory, $delegate){
		$this->factory = $factory;
		$this->delegate = $delegate;
	}
	
	public function getDelegate(){
		return $this->delegate;
	}

	/** 
	 * @return mixed
	 */		
	public function __call($method, $args){
		return $this->factory->invokeArgs($this->delegate, $method, $args);
  	}
  	
	/** 
	 * @return mixed
	 */		
	public function __get($key){
		return $this->delegate->__get($key);
	}
	
	/** 
	 * @return XClassProxy
	 */		
	public function __set($key, $value){
		$this->delegate->__set($key, $value);
		return $this;
	}

	/** 
	 * @return array
	 */	
	public function asArray(){
		return get_object_vars($this->delegate);
	}	
}
?>